#include "widget1.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QProcess>
Widget1::Widget1(QWidget *parent)
    : QWidget(parent)
{
    label1=new QLabel();
    label2=new QLabel();
    cmdLineEdit=new QLineEdit();
    confirmBtn=new QPushButton();
    cancelBtn=new QPushButton();
    label1->setText("请输入名称");
    label2->setText("打开");
    confirmBtn->setText("确定");
    cancelBtn->setText("取消");
    confirmBtn->setFixedSize(60, 30);
    cancelBtn->setFixedSize(60, 30);
    QHBoxLayout *cmdLayout = new QHBoxLayout;
    cmdLayout->addWidget(label2);
    cmdLayout->addWidget(cmdLineEdit);
    QHBoxLayout *butLayout = new QHBoxLayout;
    butLayout->addWidget(confirmBtn);
    butLayout->addWidget(cancelBtn);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(label1);
    mainLayout->addLayout(cmdLayout);
    mainLayout->addLayout(butLayout);
    setLayout(mainLayout);
    // 谁发出的信号，发出什么信号，交给谁处理，怎么处理
    //字符串绑定方式
    connect(confirmBtn, SIGNAL(clicked()), this,
            SLOT(on_confirmBtn_clicked()));
    //基于函数的绑定方式
    connect(cancelBtn, &QPushButton::clicked, this,
            &Widget1::on_cancelBtn_clicked);
    //基于lambda表达方式
}

Widget1::~Widget1() {}

void Widget1::on_confirmBtn_clicked()
{
    QString program = cmdLineEdit->text();
    QProcess *process = new QProcess;
    process->start(program);
}

void Widget1::on_cancelBtn_clicked()
{
    this->close();
}
